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: 

how to access field value from nested deep structure in badi.

0 Kudos
458

Hello Everyone,

I have been trying to access one field in deep structure.

BAdi: /SAPSLL/CUS_ECC

Method: MODIFY_IDOC_DATA

Path: /SAPSLL/ECC_CUHD_S-->/SAPSLL/ECC_CUHD_HD_S-->/SAPSLL/ECC_CUHD_PAR_T-->/SAPSLL/ECC_CUHD_PAR_S--> CTYID.

I have written code to access the value of CTYID but I'm not able to get the value of the field due to an error. (refer to screenshot)

please guide me to receive the value of the CTYID field.

Kindly assist or if a link already exists point me to it.

Thanks in advance.

4 REPLIES 4

Sandra_Rossi
Active Contributor
0 Kudos
387

Based on what you have written:

... HD[]-PAR ... 

would mean the "field PAR of the internal table", that's meaningless.

You must first access a row of an internal table, then you can access a field in this row.

e.g.

LOOP AT ... HD ASSIGNING <row>.
  " do something with <row>-PAR ...

0 Kudos
387

Hi Sandra,

Thank you for your response. I have tried your solution but it's not working. And also I'm not trying to access the field of the internal table. Actually, I'm trying to access the field from the structure.

I have gone with the loop in order to her the field. I'm putting my code as I haven't tested it. Do let me know if it is fine!

I'll update you once I get the test data to check the code.

CODE:

*-----Below code is to check if the Ultimate Consignee’s Country code is "CA".
FIELD-SYMBOLS: <ls_ecc_par> TYPE /sapsll/ecc_cuhd_par_s.
LOOP AT is_ecc_cuhd-hd-hd_par ASSIGNING <ls_ecc_par>.
IF <ls_ecc_par>-ctyid = 'CA'.

*------Below code is to check if the Licence Type is NLR or Non NLR.
FIELD-SYMBOLS: <ls_ecc_it> TYPE /sapsll/ecc_cuhd_it_s.
FIELD-SYMBOLS: <ls_ecc_doc> TYPE /sapsll/ecc_cuhd_doc_s.
LOOP AT is_ecc_cuhd-hd-hd_it ASSIGNING <ls_ecc_it>.
LOOP AT <ls_ecc_it>-it_doc ASSIGNING <ls_ecc_doc>.
IF <ls_ecc_doc>-papno = 'NLR'.
MESSAGE 'BAdi triggered' TYPE 'I'.
ENDIF.
ENDLOOP.
ENDLOOP.

ENDIF.
ENDLOOP.

387

Based on the syntax HD[] that you have used in your initial question, it means that HD is an internal table. You can't do that:

LOOP AT is_ecc_cuhd-hd-hd_it ASSIGNING ...

You can do:

LOOP AT is_ecc_cuhd-hd ASSIGNING ...

If HD is not an internal table, then you can't use HD[] and you need to clarify the exact types of all components at all levels of your complex structure.

matt
Active Contributor
0 Kudos
387

It seems you've not really got the concept of deep structures understood. Try this blog. https://blogs.sap.com/2013/10/09/deeper-dive-into-deep-structure/