ABAP Select data from SAP table /SAPAPO/PT_AOEXT_STR into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP /SAPAPO/PT_AOEXT_STR table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /SAPAPO/PT_AOEXT_STR. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the /SAPAPO/PT_AOEXT_STR table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_/SAPAPO/PT_AOEXT_STR TYPE STANDARD TABLE OF /SAPAPO/PT_AOEXT_STR,
      WA_/SAPAPO/PT_AOEXT_STR TYPE /SAPAPO/PT_AOEXT_STR,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: </SAPAPO/PT_AOEXT_STR> TYPE /SAPAPO/PT_AOEXT_STR.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/SAPAPO/PT_AOEXT_STR.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SAPAPO/PT_AOEXT_STR
  INTO TABLE IT_/SAPAPO/PT_AOEXT_STR.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SAPAPO/PT_AOEXT_STR
*  INTO TABLE @DATA(IT_/SAPAPO/PT_AOEXT_STR2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_/SAPAPO/PT_AOEXT_STR INDEX 1 INTO DATA(WA_/SAPAPO/PT_AOEXT_STR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SAPAPO/PT_AOEXT_STR ASSIGNING </SAPAPO/PT_AOEXT_STR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/PT_AOEXT_STR>-MARKED = 1.
</SAPAPO/PT_AOEXT_STR>-LOCNO = 1.
</SAPAPO/PT_AOEXT_STR>-RESNA = 1.
</SAPAPO/PT_AOEXT_STR>-MATNR = 1.
</SAPAPO/PT_AOEXT_STR>-MAKTX = 1.
ENDLOOP.

LOOP AT IT_/SAPAPO/PT_AOEXT_STR INTO WA_/SAPAPO/PT_AOEXT_STR.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SAPAPO/PT_AOEXT_STR-CATNA, sy-vline,
WA_/SAPAPO/PT_AOEXT_STR-PLANR, sy-vline,
WA_/SAPAPO/PT_AOEXT_STR-PPENA, sy-vline,
WA_/SAPAPO/PT_AOEXT_STR-MEOUT, sy-vline,
WA_/SAPAPO/PT_AOEXT_STR-QUANT, sy-vline,
WA_/SAPAPO/PT_AOEXT_STR-QREAL, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/PT_AOEXT_STR you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/SAPAPO/PT_AOEXT_STR TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/SAPAPO/PT_AOEXT_STR INTO WA_/SAPAPO/PT_AOEXT_STR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SAPAPO/PT_AOEXT_STR-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/PT_AOEXT_STR-MATNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field MEOUT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPAPO/PT_AOEXT_STR-MEOUT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/PT_AOEXT_STR-MEOUT.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/SAPAPO/PT_AOEXT_STR_STR,
MARKED TYPE STRING,
LOCNO TYPE STRING,
RESNA TYPE STRING,
MATNR TYPE STRING,
MAKTX TYPE STRING,
CATNA TYPE STRING,
PLANR TYPE STRING,
PPENA TYPE STRING,
MEOUT TYPE STRING,
QUANT TYPE STRING,
QREAL TYPE STRING,
QORIG TYPE STRING,
QCNFR TYPE STRING,
ORDNO TYPE STRING,
POSNO TYPE STRING,
LINNO TYPE STRING,
OOUTD TYPE STRING,
OOUTT TYPE STRING,
PRODUCABLE TYPE STRING,
OUTPUT_FIXED TYPE STRING,
INPUT_FIXED TYPE STRING,
PART_DELIVERED TYPE STRING,
FINAL_DELIVERY TYPE STRING,
UNPLANNED TYPE STRING,
RELEASED TYPE STRING,
DATE_FIXED TYPE STRING,
STARTED TYPE STRING,
PART_CONFIRMED TYPE STRING,
FINAL_CONFIRMED TYPE STRING,
INTERRUPTED TYPE STRING,
ASTAD TYPE STRING,
ASTAT TYPE STRING,
ASTAS TYPE STRING,
ACNFD TYPE STRING,
ACNFT TYPE STRING,
AENDD TYPE STRING,
AENDT TYPE STRING,
TZONE TYPE STRING,
PT_ACTDUR_DAYS TYPE STRING,
PT_ACTDUR TYPE STRING,
ATEXT TYPE STRING,
ACTID TYPE STRING,
ACTYP TYPE STRING,
CV_EX TYPE STRING,
PROPS TYPE STRING,
B_CDP TYPE STRING,
BACKLOG TYPE STRING,
INPROW TYPE STRING,
CAPACITY_DEMAND TYPE STRING,
BUCKET_DEMAND TYPE STRING,
JOINT TYPE STRING,
EFFECTIVITY_MODE TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/PT_AOEXT_STR_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-MARKED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-LOCNO sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-RESNA sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-MATNR sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-MAKTX sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-CATNA sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PLANR sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PPENA sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-MEOUT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-QUANT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-QREAL sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-QORIG sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-QCNFR sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ORDNO sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-POSNO sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-LINNO sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-OOUTD sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-OOUTT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PRODUCABLE sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-OUTPUT_FIXED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-INPUT_FIXED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PART_DELIVERED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-FINAL_DELIVERY sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-UNPLANNED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-RELEASED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-DATE_FIXED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-STARTED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PART_CONFIRMED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-FINAL_CONFIRMED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-INTERRUPTED sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ASTAD sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ASTAT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ASTAS sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ACNFD sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ACNFT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-AENDD sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-AENDT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-TZONE sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PT_ACTDUR_DAYS sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PT_ACTDUR sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ATEXT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ACTID sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-ACTYP sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-CV_EX sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-PROPS sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-B_CDP sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-BACKLOG sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-INPROW sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-CAPACITY_DEMAND sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-BUCKET_DEMAND sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-JOINT sy-vline
WA_/SAPAPO/PT_AOEXT_STR_STR-EFFECTIVITY_MODE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.