ABAP Select data from SAP table PC280 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 PC280 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 PC280. 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 PC280 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_PC280 TYPE STANDARD TABLE OF PC280,
      WA_PC280 TYPE PC280,
      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: <PC280> TYPE PC280.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM PC280
  INTO TABLE IT_PC280.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PC280
*  INTO TABLE @DATA(IT_PC2802).
*--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_PC280 INDEX 1 INTO DATA(WA_PC2802).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PC280 ASSIGNING <PC280>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PC280>-CNTR1 = 1.
<PC280>-CNTR2 = 1.
<PC280>-BEGDA = 1.
<PC280>-ENDDA = 1.
<PC280>-ANSTA = 1.
ENDLOOP.

LOOP AT IT_PC280 INTO WA_PC280.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PC280-JUPER, sy-vline,
WA_PC280-BUKRS, sy-vline,
WA_PC280-WERKS, sy-vline,
WA_PC280-BTRTL, sy-vline,
WA_PC280-PERSG, sy-vline,
WA_PC280-PERSK, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PC280 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_PC280 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_PC280 INTO WA_PC280. *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 ISOLA, internal->external for field RSZLA CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_PC280-RSZLA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PC280-RSZLA.
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_PC280_STR,
CNTR1 TYPE STRING,
CNTR2 TYPE STRING,
BEGDA TYPE STRING,
ENDDA TYPE STRING,
ANSTA TYPE STRING,
JUPER TYPE STRING,
BUKRS TYPE STRING,
WERKS TYPE STRING,
BTRTL TYPE STRING,
PERSG TYPE STRING,
PERSK TYPE STRING,
PERID TYPE STRING,
ENTKM TYPE STRING,
WKWNG TYPE STRING,
TEILK TYPE STRING,
EMPCT TYPE STRING,
DYSCH TYPE STRING,
ZTERF TYPE STRING,
SCHKZ TYPE STRING,
WOSTD TYPE STRING,
MOSTD TYPE STRING,
ARBST TYPE STRING,
BSGRD TYPE STRING,
BESTE TYPE STRING,
BERGM TYPE STRING,
BEREG TYPE STRING,
CTTYP TYPE STRING,
ARBER TYPE STRING,
BEANC TYPE STRING,
BEAAN TYPE STRING,
BETIM TYPE STRING,
BEGWU TYPE STRING,
WAERS TYPE STRING,
BEUWG TYPE STRING,
BECAO TYPE STRING,
BEGPC TYPE STRING,
BECNR TYPE STRING,
BEMCH TYPE STRING,
BEGFB TYPE STRING,
BEGGH TYPE STRING,
BREGM TYPE STRING,
RSZBL TYPE STRING,
RSZGL TYPE STRING,
RSZKE TYPE STRING,
RSZNA TYPE STRING,
RSZPN TYPE STRING,
RSZRR TYPE STRING,
RSZVW TYPE STRING,
RSZCA TYPE STRING,
RSZFF TYPE STRING,
RSZFS TYPE STRING,
RSZKN TYPE STRING,
RSZLM TYPE STRING,
RSZNO TYPE STRING,
RSZSP TYPE STRING,
RSZWG TYPE STRING,
BVETL TYPE STRING,
BVFAM TYPE STRING,
BVEKI TYPE STRING,
FIXVA TYPE STRING,
PPAID TYPE STRING,
BEUW2 TYPE STRING,
REMES TYPE STRING,
EMPLP TYPE STRING,
APTYP TYPE STRING,
RETIR TYPE STRING,
MODRM TYPE STRING,
REDST TYPE STRING,
OSSIN TYPE STRING,
OREDD TYPE STRING,
ASSIN TYPE STRING,
CORIG TYPE STRING,
RFSCH TYPE STRING,
LOCUN TYPE STRING,
RSKAC TYPE STRING,
ALLCD TYPE STRING,
ALLST TYPE STRING,
BVCOA TYPE STRING,
MARBR TYPE STRING,
NACEC TYPE STRING,
OLDRR TYPE STRING,
EERST TYPE STRING,
RDCST TYPE STRING,
REMTY TYPE STRING,
CAPEX TYPE STRING,
DISPD TYPE STRING,
CFWPT TYPE STRING,
DISHW TYPE STRING,
RCAIN TYPE STRING,
STYPE TYPE STRING,
TMPFT TYPE STRING,
NMEDT TYPE STRING,
PSPCC TYPE STRING,
ILLDT TYPE STRING,
SEREX TYPE STRING,
CARME TYPE STRING,
SEXSD TYPE STRING,
TRASI TYPE STRING,
PERSM TYPE STRING,
SECDT TYPE STRING,
SUPCE TYPE STRING,
FLYCL TYPE STRING,
PSTWO TYPE STRING,
DENOD TYPE STRING,
ESWDS TYPE STRING,
ESMWH TYPE STRING,
RSZLA TYPE STRING,
REAME TYPE STRING,END OF T_EKKO_STR. DATA: WA_PC280_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_PC280_STR-CNTR1 sy-vline
WA_PC280_STR-CNTR2 sy-vline
WA_PC280_STR-BEGDA sy-vline
WA_PC280_STR-ENDDA sy-vline
WA_PC280_STR-ANSTA sy-vline
WA_PC280_STR-JUPER sy-vline
WA_PC280_STR-BUKRS sy-vline
WA_PC280_STR-WERKS sy-vline
WA_PC280_STR-BTRTL sy-vline
WA_PC280_STR-PERSG sy-vline
WA_PC280_STR-PERSK sy-vline
WA_PC280_STR-PERID sy-vline
WA_PC280_STR-ENTKM sy-vline
WA_PC280_STR-WKWNG sy-vline
WA_PC280_STR-TEILK sy-vline
WA_PC280_STR-EMPCT sy-vline
WA_PC280_STR-DYSCH sy-vline
WA_PC280_STR-ZTERF sy-vline
WA_PC280_STR-SCHKZ sy-vline
WA_PC280_STR-WOSTD sy-vline
WA_PC280_STR-MOSTD sy-vline
WA_PC280_STR-ARBST sy-vline
WA_PC280_STR-BSGRD sy-vline
WA_PC280_STR-BESTE sy-vline
WA_PC280_STR-BERGM sy-vline
WA_PC280_STR-BEREG sy-vline
WA_PC280_STR-CTTYP sy-vline
WA_PC280_STR-ARBER sy-vline
WA_PC280_STR-BEANC sy-vline
WA_PC280_STR-BEAAN sy-vline
WA_PC280_STR-BETIM sy-vline
WA_PC280_STR-BEGWU sy-vline
WA_PC280_STR-WAERS sy-vline
WA_PC280_STR-BEUWG sy-vline
WA_PC280_STR-BECAO sy-vline
WA_PC280_STR-BEGPC sy-vline
WA_PC280_STR-BECNR sy-vline
WA_PC280_STR-BEMCH sy-vline
WA_PC280_STR-BEGFB sy-vline
WA_PC280_STR-BEGGH sy-vline
WA_PC280_STR-BREGM sy-vline
WA_PC280_STR-RSZBL sy-vline
WA_PC280_STR-RSZGL sy-vline
WA_PC280_STR-RSZKE sy-vline
WA_PC280_STR-RSZNA sy-vline
WA_PC280_STR-RSZPN sy-vline
WA_PC280_STR-RSZRR sy-vline
WA_PC280_STR-RSZVW sy-vline
WA_PC280_STR-RSZCA sy-vline
WA_PC280_STR-RSZFF sy-vline
WA_PC280_STR-RSZFS sy-vline
WA_PC280_STR-RSZKN sy-vline
WA_PC280_STR-RSZLM sy-vline
WA_PC280_STR-RSZNO sy-vline
WA_PC280_STR-RSZSP sy-vline
WA_PC280_STR-RSZWG sy-vline
WA_PC280_STR-BVETL sy-vline
WA_PC280_STR-BVFAM sy-vline
WA_PC280_STR-BVEKI sy-vline
WA_PC280_STR-FIXVA sy-vline
WA_PC280_STR-PPAID sy-vline
WA_PC280_STR-BEUW2 sy-vline
WA_PC280_STR-REMES sy-vline
WA_PC280_STR-EMPLP sy-vline
WA_PC280_STR-APTYP sy-vline
WA_PC280_STR-RETIR sy-vline
WA_PC280_STR-MODRM sy-vline
WA_PC280_STR-REDST sy-vline
WA_PC280_STR-OSSIN sy-vline
WA_PC280_STR-OREDD sy-vline
WA_PC280_STR-ASSIN sy-vline
WA_PC280_STR-CORIG sy-vline
WA_PC280_STR-RFSCH sy-vline
WA_PC280_STR-LOCUN sy-vline
WA_PC280_STR-RSKAC sy-vline
WA_PC280_STR-ALLCD sy-vline
WA_PC280_STR-ALLST sy-vline
WA_PC280_STR-BVCOA sy-vline
WA_PC280_STR-MARBR sy-vline
WA_PC280_STR-NACEC sy-vline
WA_PC280_STR-OLDRR sy-vline
WA_PC280_STR-EERST sy-vline
WA_PC280_STR-RDCST sy-vline
WA_PC280_STR-REMTY sy-vline
WA_PC280_STR-CAPEX sy-vline
WA_PC280_STR-DISPD sy-vline
WA_PC280_STR-CFWPT sy-vline
WA_PC280_STR-DISHW sy-vline
WA_PC280_STR-RCAIN sy-vline
WA_PC280_STR-STYPE sy-vline
WA_PC280_STR-TMPFT sy-vline
WA_PC280_STR-NMEDT sy-vline
WA_PC280_STR-PSPCC sy-vline
WA_PC280_STR-ILLDT sy-vline
WA_PC280_STR-SEREX sy-vline
WA_PC280_STR-CARME sy-vline
WA_PC280_STR-SEXSD sy-vline
WA_PC280_STR-TRASI sy-vline
WA_PC280_STR-PERSM sy-vline
WA_PC280_STR-SECDT sy-vline
WA_PC280_STR-SUPCE sy-vline
WA_PC280_STR-FLYCL sy-vline
WA_PC280_STR-PSTWO sy-vline
WA_PC280_STR-DENOD sy-vline
WA_PC280_STR-ESWDS sy-vline
WA_PC280_STR-ESMWH sy-vline
WA_PC280_STR-RSZLA sy-vline
WA_PC280_STR-REAME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.