Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Excel Template mapping to internal table

calvinkarlo
Explorer

I have an requirement to upload excel with dynamic template from abap program i.e..the excel template won't be a constant, it might change.

move gt_intern[] TO gt_intern2[].
DELETE gt_intern2 WHERE row NE 1.

I need to get the get the fieldnames "LOC" and fields starts with "Charge for"

I need the fields that starts with "Charge for" for calculation

so i use this logic

IF gwa_intern2-value+(10) EQ 'Charge for' OR gwa_intern-Value EQ 'Loc'.

MOVE : gwa_intern2-col to gwa_intern3-col,
gwa_intern2-Value to gwa_intern3-value.
APPEND gwa_intern3 TO gt_intern3.

then

loop at gt_intern into gwa_intern.
read table gt_intern3 ASSIGNING FIELD-SYMBOL(<FS_MA>) with key col = gwa_intern-col.
if sy-subrc = 0.

append to GT_BODY.

After uploading the invoice and select necessary information from (Loc, Charge for: etc...) The question is how can I map the fields and their respective values from excel to another internal table.

I tried this logic

If Field01 = 'Charge for: Con'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

else if Field01 = 'Charge for Dg'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

else if field01 ='Charge for FRT'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

endif.

If Field02 = 'Charge for: Con'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

else if Field02 = 'Charge for Dg'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

else if field02 ='Charge for FRT'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

endif.

If Field03 = 'Charge for: Con'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

else if Field03 = 'Charge for Dg'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

else if field03='Charge for FRT'

MOVE: <FS_INPTFL>-FIELD01 TO E_invoice-BASE.

endif.

The things is I have 24 fields so I need to do this 24 times.

is there another way to identify specific charges?

2 REPLIES 2

abo
Active Contributor
0 Kudos

Check out the many blogposts and questions related to #abap2xlsx

Sandra_Rossi
Active Contributor
0 Kudos

I don't get why GT_BODY contains these non-functional names FIELD01, etc.

Why don't you just indicate the component names you want, e.g. LOC, CHARGE_FOR_CON, etc.

I don't know your ABAP version, let's admit it's an old one (< 7.40):

read table GT_INTERN INTO LS_INTERN_LOC with key value = 'Loc'.
read table GT_INTERN INTO LS_INTERN_CON with key value = 'Charge for: CON'.
read table GT_INTERN INTO LS_INTERN_DG with key value = 'Charge for: DG'.
read table GT_INTERN INTO LS_INTERN_FRT with key value = 'Charge for: FRT'. LOOP AT gt_intern INTO ls_intern WHERE row >= 2.
CASE ls_intern-col.
WHEN ls_intern_loc-col. E_invoice-LOC = ls_intern-value. WHEN ls_intern_loc-con. E_invoice-charge_for_con = ls_intern-value. WHEN ls_intern_loc-dg. E_invoice-charge_for_dg = ls_intern-value. WHEN ls_intern_loc-frt. E_invoice-charge_for_frt = ls_intern-value. ENDCASE. ...

Remarks:

  • Your variable names are awful, they should express the functional meaning.
  • MOVE has been obsolete for 15 years.