ABAP Select data from SAP table FC05_S_POSGROUP_S4H 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 FC05_S_POSGROUP_S4H 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 FC05_S_POSGROUP_S4H. 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 FC05_S_POSGROUP_S4H 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_FC05_S_POSGROUP_S4H TYPE STANDARD TABLE OF FC05_S_POSGROUP_S4H, WA_FC05_S_POSGROUP_S4H TYPE FC05_S_POSGROUP_S4H, 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: <FC05_S_POSGROUP_S4H> TYPE FC05_S_POSGROUP_S4H. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_FC05_S_POSGROUP_S4H. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM FC05_S_POSGROUP_S4H INTO TABLE IT_FC05_S_POSGROUP_S4H. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM FC05_S_POSGROUP_S4H * INTO TABLE @DATA(IT_FC05_S_POSGROUP_S4H2). *--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_FC05_S_POSGROUP_S4H INDEX 1 INTO DATA(WA_FC05_S_POSGROUP_S4H2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_FC05_S_POSGROUP_S4H ASSIGNING <FC05_S_POSGROUP_S4H>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<FC05_S_POSGROUP_S4H>-RBUNIT = 1.
<FC05_S_POSGROUP_S4H>-RBUPTR = 1.
<FC05_S_POSGROUP_S4H>-RITEM = 1.
<FC05_S_POSGROUP_S4H>-RTCUR = 1.
<FC05_S_POSGROUP_S4H>-RUNIT = 1.
ENDLOOP. LOOP AT IT_FC05_S_POSGROUP_S4H INTO WA_FC05_S_POSGROUP_S4H. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_FC05_S_POSGROUP_S4H-SITYP, sy-vline,
WA_FC05_S_POSGROUP_S4H-SUBIT, sy-vline,
WA_FC05_S_POSGROUP_S4H-YRACQ, sy-vline,
WA_FC05_S_POSGROUP_S4H-PRACQ, sy-vline,
WA_FC05_S_POSGROUP_S4H-DOCTY, sy-vline,
WA_FC05_S_POSGROUP_S4H-GCURR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FC05_S_POSGROUP_S4H 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_FC05_S_POSGROUP_S4H 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_FC05_S_POSGROUP_S4H INTO WA_FC05_S_POSGROUP_S4H. *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 AFIMC, internal->external for field RBUNIT CALL FUNCTION 'CONVERSION_EXIT_AFIMC_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RBUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RBUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AFIMC, internal->external for field RBUPTR CALL FUNCTION 'CONVERSION_EXIT_AFIMC_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RBUPTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RBUPTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit BFIMC, internal->external for field RITEM CALL FUNCTION 'CONVERSION_EXIT_BFIMC_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RITEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field RUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field YRACQ CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-YRACQ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-YRACQ.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RACCT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RACCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RACCT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RCNTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RCNTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RCNTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-PRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-PRCTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SEGMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-SEGMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-SEGMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SCNTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-SCNTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-SCNTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PPRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-PPRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-PPRCTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RASSC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-RASSC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-RASSC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PSEGMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-PSEGMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-PSEGMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AUFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-AUFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-AUFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-KUNNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-LIFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSP, internal->external for field PS_PSP_PNR CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-PS_PSP_PNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-PS_PSP_PNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field PS_POSID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-PS_POSID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-PS_POSID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field PS_PSPID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-PS_PSPID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-PS_PSPID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR_COPA CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-MATNR_COPA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-MATNR_COPA.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNRE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-KUNRE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-KUNRE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNWE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FC05_S_POSGROUP_S4H-KUNWE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FC05_S_POSGROUP_S4H-KUNWE.
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_FC05_S_POSGROUP_S4H_STR,
RBUNIT TYPE STRING,
RBUPTR TYPE STRING,
RITEM TYPE STRING,
RTCUR TYPE STRING,
RUNIT TYPE STRING,
SITYP TYPE STRING,
SUBIT TYPE STRING,
YRACQ TYPE STRING,
PRACQ TYPE STRING,
DOCTY TYPE STRING,
GCURR TYPE STRING,
KTOPL TYPE STRING,
RACCT TYPE STRING,
XBLNR TYPE STRING,
ZUONR TYPE STRING,
RCNTR TYPE STRING,
PRCTR TYPE STRING,
RFAREA TYPE STRING,
RBUSA TYPE STRING,
KOKRS TYPE STRING,
SEGMENT TYPE STRING,
SCNTR TYPE STRING,
PPRCTR TYPE STRING,
SFAREA TYPE STRING,
SBUSA TYPE STRING,
RASSC TYPE STRING,
PSEGMENT TYPE STRING,
AUFNR TYPE STRING,
KUNNR TYPE STRING,
LIFNR TYPE STRING,
MATNR TYPE STRING,
MATKL_MM TYPE STRING,
WERKS TYPE STRING,
RMVCT TYPE STRING,
PS_PSP_PNR TYPE STRING,
PS_POSID TYPE STRING,
PS_PSPID TYPE STRING,
FKART TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
SPART TYPE STRING,
MATNR_COPA TYPE STRING,
MATKL TYPE STRING,
KDGRP TYPE STRING,
LAND1 TYPE STRING,
BRSCH TYPE STRING,
BZIRK TYPE STRING,
KUNRE TYPE STRING,
KUNWE TYPE STRING,
KONZS TYPE STRING,END OF T_EKKO_STR. DATA: WA_FC05_S_POSGROUP_S4H_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_FC05_S_POSGROUP_S4H_STR-RBUNIT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RBUPTR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RITEM sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RTCUR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RUNIT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SITYP sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SUBIT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-YRACQ sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PRACQ sy-vline
WA_FC05_S_POSGROUP_S4H_STR-DOCTY sy-vline
WA_FC05_S_POSGROUP_S4H_STR-GCURR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KTOPL sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RACCT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-XBLNR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-ZUONR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RCNTR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PRCTR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RFAREA sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RBUSA sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KOKRS sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SEGMENT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SCNTR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PPRCTR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SFAREA sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SBUSA sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RASSC sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PSEGMENT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-AUFNR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KUNNR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-LIFNR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-MATNR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-MATKL_MM sy-vline
WA_FC05_S_POSGROUP_S4H_STR-WERKS sy-vline
WA_FC05_S_POSGROUP_S4H_STR-RMVCT sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PS_PSP_PNR sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PS_POSID sy-vline
WA_FC05_S_POSGROUP_S4H_STR-PS_PSPID sy-vline
WA_FC05_S_POSGROUP_S4H_STR-FKART sy-vline
WA_FC05_S_POSGROUP_S4H_STR-VKORG sy-vline
WA_FC05_S_POSGROUP_S4H_STR-VTWEG sy-vline
WA_FC05_S_POSGROUP_S4H_STR-SPART sy-vline
WA_FC05_S_POSGROUP_S4H_STR-MATNR_COPA sy-vline
WA_FC05_S_POSGROUP_S4H_STR-MATKL sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KDGRP sy-vline
WA_FC05_S_POSGROUP_S4H_STR-LAND1 sy-vline
WA_FC05_S_POSGROUP_S4H_STR-BRSCH sy-vline
WA_FC05_S_POSGROUP_S4H_STR-BZIRK sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KUNRE sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KUNWE sy-vline
WA_FC05_S_POSGROUP_S4H_STR-KONZS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.