falsch gesetztes loop!?

Alles rund um die Sprache ABAP®: Funktionsbausteine, Listen, ALV
8 Beiträge • Seite 1 von 1
8 Beiträge Seite 1 von 1

falsch gesetztes loop!?

Beitrag von BabsiCSC (ForumUser / 86 / 0 / 0 ) »
Hallo,

Ich habe ein Problem mit einem loop.
Bzw. ich vermute mal, dass mein zweites loop (über makt) falsch gesetzt ist.
Oder?
- im report bekomme ich die richtige Ausgabe
- wenn ich über ALV ausgeben will, bekomme ich jedoch keine Ausgabe, sondern eben nur den ersten Datensatz (siehe screenshot) ..
Bitte um Hilfe
thx,
lg

Mein derzeitiger Code sieht so aus -->

Code: Alles auswählen.

REPORT  z_mmstamm_bl LINE-SIZE 132.

*** I N C L U D E S ****************************************************
INCLUDE <icon>.

*** D A T E N D E K L A R A T I O N ************************************
DATA:
  g_it_data TYPE TABLE OF zsss_mmstamm_bl,
  g_wa_data TYPE zsss_mmstamm_bl,
  g_it_makt TYPE TABLE OF makt,
  g_wa_makt TYPE makt.

DATA:
  g_zaehler TYPE i.

DATA:
  ok_code LIKE sy-ucomm,
  g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
  grid1 TYPE REF TO cl_gui_alv_grid,
  g_repid LIKE sy-repid,
* Define a structure of type LVC_S_LAYO.
  gs_layout TYPE lvc_s_layo,
  g_custom_container TYPE REF TO cl_gui_custom_container.
** Define the fieldcatalog
*  gt_field TYPE lvc_t_fcat,
** Define the workarea
*  gw_field TYPE lvc_s_fcat.

DATA:
  g_light TYPE c.

* The name of the additional field has to be acquainted to ALV
* in 'gs_layout-excp_fname' which is of type lvc_cifnm.
* 'g_lights_name' is defined for that purpose
DATA:
  g_lights_name TYPE lvc_cifnm VALUE 'LIGHT'.

*** S E L E K T I O N E N **********************************************
* Selectionscreen
SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME TITLE text-001.
SELECT-OPTIONS:
  so_matnr FOR g_wa_data-matnr.
PARAMETER:
  pa_alv TYPE c RADIOBUTTON GROUP radi,
  pa_wri TYPE c RADIOBUTTON GROUP radi.
SELECTION-SCREEN END OF BLOCK selection.

*This is written on the top of the page
TOP-OF-PAGE.

* It should only be written in the report version
  IF pa_wri = 'X'.

    WRITE:/1 'List of the materials',
*     Point of run time of the report, date
      40 'Date: ', sy-datum,
*     Point of run time of the report, time
      60 'Time: ', sy-uzeit,
      100 'User: ', sy-uname.
    WRITE: /.
    WRITE: /1 'Material Number',
      20 'Material Description (Short Text)',
      70 'Number of the short text',
      100 'Section',
      120 'Status'.
    WRITE: /.

  ENDIF.

START-OF-SELECTION.

  CLEAR: g_it_data,
         g_it_makt.

  SELECT matnr spart FROM mara INTO CORRESPONDING FIELDS OF TABLE g_it_data
      WHERE matnr IN so_matnr.

  SELECT * FROM makt INTO TABLE g_it_makt
    WHERE matnr IN so_matnr.


  LOOP AT g_it_data INTO g_wa_data.


    [b]LOOP AT g_it_makt INTO g_wa_makt.

      IF g_wa_data-matnr = g_wa_makt-matnr.

        IF g_wa_makt-spras = sy-langu.
          g_wa_data-maktx = g_wa_makt-maktx.
        ENDIF.

        g_wa_data-counter = g_wa_data-counter + 1.

      ENDIF.


      IF g_wa_data-spart = 'Z1'.
        g_wa_data-light = '1'.
      ELSEIF g_wa_data-spart = 'LF'.
        g_wa_data-light = '2'.
      ELSE.
        g_wa_data-light = '3'.
      ENDIF.

      MODIFY g_it_data FROM g_wa_data.

    ENDLOOP.[/b]

[b]    IF pa_alv = 'X'.

*     Set initial dynpro
      CALL SCREEN 100.[/b]    
ELSEIF pa_wri = 'X'.

*     Output of the data records
      WRITE: /1 g_wa_data-matnr,
        20 g_wa_data-maktx,
        70 g_wa_data-counter,
        100 g_wa_data-spart.

      IF g_wa_data-spart = 'Z1'.
        WRITE 120 icon_red_light AS ICON.
      ELSEIF g_wa_data-spart = 'LF'.
        WRITE 120 icon_yellow_light AS ICON.
      ELSE.
        WRITE 120 icon_green_light AS ICON.
      ENDIF.

*     Count up the data records
      g_zaehler = g_zaehler + 1.

    ENDIF.


  ENDLOOP.


END-OF-SELECTION.

* It should only be written in the report version
  IF pa_wri = 'X'.

    WRITE: /.
    WRITE:/1 'Number of the short text: ', g_wa_data-counter,
    70 'Data records: ', g_zaehler,
    110 'Page: ', sy-pagno.
    WRITE: /.

  ENDIF.

*This is written on the end of the page
END-OF-PAGE.
*----------------------------------------------------------------------*
*  MODULE PBO OUTPUT
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'MAIN100'.
  g_repid = sy-repid.
  IF g_custom_container IS INITIAL.
*   Set a value for field LIGHT for each line of your output table.
*   You do not necessarily need to define a field catalog if
*   the rest of your output table is represented by a DDIC structure.
    CREATE OBJECT g_custom_container
           EXPORTING container_name = g_container
    EXCEPTIONS
        cntl_error = 1
        cntl_system_error = 2
        create_error = 3
        lifetime_error = 4
        lifetime_dynpro_dynpro_link = 5.
    IF sy-subrc NE 0.
*   Add your handling, for example
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = g_repid
          txt2  = sy-subrc
          txt1  = 'The control could not be created'(510).
    ENDIF.
*   Create an instance of alv control
    CREATE OBJECT grid1
           EXPORTING i_parent = g_custom_container.
*..............................................
*set some layout-values (Structure LVC_S_LAYO)
*..............................................
*   Set a titlebar for the grid control
    gs_layout-grid_title = 'Materials'(100).
*   Set field EXCP_FNAME of the structure of type LVC_S_LAYO
*   with the name of your additional field.
    gs_layout-excp_fname = g_lights_name.

    gs_layout-excp_rolln = 'ALV_LIGHT'.
*    gs_layout-excp_led   = 'X'.

    gs_layout-zebra = 'X'.
*.............................
* show table on ALV Control
*.............................
*   Provide your Layout-Structure when calling
*   'set_table_for_first_display' (Parameter IS_LAYOUT).
    CALL METHOD grid1->set_table_for_first_display
  EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
    i_structure_name              = 'ZSSS_MMSTAMM_BL'
*    IS_VARIANT                    =
*    I_SAVE                        =
*    I_DEFAULT                     = 'X'
    is_layout                     = gs_layout
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
      CHANGING
        it_outtab                     = g_it_data
*        it_fieldcatalog               = gt_field
*    IT_SORT                       =
*    IT_FILTER                     =
*  EXCEPTIONS
*    INVALID_PARAMETER_COMBINATION = 1
*    PROGRAM_ERROR                 = 2
*    TOO_MANY_LINES                = 3
*    others                        = 4
            .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  ENDIF.

*Control Framework flushes at the end of PBO automatically!
ENDMODULE.                 " PBO  OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
* To react on oi_custom_events:
  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN OTHERS.
* Do nothing
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "PAI INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
*  CALL METHOD G_CUSTOM_CONTAINER->FREE.
*  CALL METHOD CL_GUI_CFW=>FLUSH.
  LEAVE PROGRAM.
ENDFORM.                    "EXIT_PROGRAM

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Beitrag von DeathGuardian (Expert / 759 / 0 / 3 ) »
Mach doch einfach aus den 2 Selects gleich ein SELECT...JOIN.
Ersparrt einiges! ;)

Beitrag von BabsiCSC (ForumUser / 86 / 0 / 0 ) »
Hello,

Ja, das mit dem select - join, das hatte ich vorher schon ...
Aber das ist in dem Fall unerwünscht, bzw. vom Kunden "nicht gerne gesehen". Deshalb habe ich es auf zwei selects aufgeteilt.
Mit inner join funkt. auch, ich weiß .. - aber mit den zwei selects da happert's :( ..

Das muss doch mit den beiden selects auch funktionieren, oder?

thx,
lg

Beitrag von index (ForumUser / 17 / 0 / 0 ) »
Hi

du loopst über deine itab und je loopschleife springst du in dein Dynpro, und natürlich auch bei der 1.Zeile. Vielleicht solltest du zuerst deine Itab füllen und dann die Ausgabe im ALV oder eine Listausgabe machen.

Michael

Beitrag von BabsiCSC (ForumUser / 86 / 0 / 0 ) »
Hallo Michael,

Danke für deine Hilfe!
Jedoch hab' ich noch eine Frage, um das Ganze zu konkretisieren .. :? -->
Das was du mir geschrieben hast, das mache ich doch schon so wie du das meinst, oder??? :(
- weil ich befülle sie ja vorher schon mit dem into ... , danach loope ich, und zum Schluss mache ich die Ausgabe !?!!
... SELECT matnr spart FROM mara INTO CORRESPONDING FIELDS OF TABLE g_it_data
WHERE matnr IN so_matnr.

SELECT * FROM makt INTO TABLE g_it_makt
WHERE matnr IN so_matnr.


LOOP AT g_it_data INTO g_wa_data.


LOOP AT g_it_makt INTO g_wa_makt.

IF g_wa_data-matnr = g_wa_makt-matnr.

IF g_wa_makt-spras = sy-langu.
g_wa_data-maktx = g_wa_makt-maktx.
ENDIF.

g_wa_data-counter = g_wa_data-counter + 1.

ENDIF.


IF g_wa_data-spart = 'Z1'.
g_wa_data-light = '1'.
ELSEIF g_wa_data-spart = 'LF'.
g_wa_data-light = '2'.
ELSE.
g_wa_data-light = '3'.
ENDIF.

MODIFY g_it_data FROM g_wa_data.

ENDLOOP.


IF pa_alv = 'X'.

* Set initial dynpro
CALL SCREEN 100.

ELSEIF pa_wri = 'X'.

....
--> Oder wie hast du das jetzt gemeint??

Danke!
lg

Richtiges Ergebnis

Beitrag von BabsiCSC (ForumUser / 86 / 0 / 0 ) »
Hallo,

Danke für die Hilfe!

-> Hab' das jetzt mit dem loop anders gelöst, so funkt. das auch, und zwar sieht der richtige Code dafür so aus:

Code: Alles auswählen.

REPORT  z_mmstamm_bl LINE-SIZE 132.

*** I N C L U D E S ****************************************************
INCLUDE <icon>.

*** D A T E N D E K L A R A T I O N ************************************
DATA:
  g_it_data TYPE TABLE OF zsss_mmstamm_bl,
  g_wa_data TYPE zsss_mmstamm_bl,
  g_it_makt TYPE TABLE OF makt,
  g_wa_makt TYPE makt.

DATA:
  g_zaehler TYPE i.

DATA:
  ok_code LIKE sy-ucomm,
  g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
  grid1 TYPE REF TO cl_gui_alv_grid,
  g_repid LIKE sy-repid,
* Define a structure of type LVC_S_LAYO.
  gs_layout TYPE lvc_s_layo,
  g_custom_container TYPE REF TO cl_gui_custom_container.
** Define the fieldcatalog
*  gt_field TYPE lvc_t_fcat,
** Define the workarea
*  gw_field TYPE lvc_s_fcat.

DATA:
  g_light TYPE c.

* The name of the additional field has to be acquainted to ALV
* in 'gs_layout-excp_fname' which is of type lvc_cifnm.
* 'g_lights_name' is defined for that purpose
DATA:
  g_lights_name TYPE lvc_cifnm VALUE 'LIGHT'.

*** S E L E K T I O N E N **********************************************
* Selectionscreen
SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME TITLE text-001.
SELECT-OPTIONS:
  so_matnr FOR g_wa_data-matnr.
PARAMETER:
  pa_alv TYPE c RADIOBUTTON GROUP radi,
  pa_wri TYPE c RADIOBUTTON GROUP radi.
SELECTION-SCREEN END OF BLOCK selection.

*This is written on the top of the page
TOP-OF-PAGE.

* It should only be written in the report version
  IF pa_wri = 'X'.

    WRITE:/1 'List of the materials',
*     Point of run time of the report, date
      40 'Date: ', sy-datum,
*     Point of run time of the report, time
      60 'Time: ', sy-uzeit,
      100 'User: ', sy-uname.
    WRITE: /.
    WRITE: /1 'Material Number',
      20 'Material Description (Short Text)',
      70 'Number of the short text',
      100 'Section',
      120 'Status'.
    WRITE: /.

  ENDIF.

START-OF-SELECTION.

  CLEAR: g_it_data,
         g_it_makt.

  SELECT matnr spart FROM mara INTO CORRESPONDING FIELDS OF TABLE g_it_data
      WHERE matnr IN so_matnr.

  SELECT * FROM makt INTO TABLE g_it_makt
    WHERE matnr IN so_matnr.


  LOOP AT g_it_data INTO g_wa_data.


    LOOP AT g_it_makt INTO g_wa_makt.

      IF g_wa_data-matnr = g_wa_makt-matnr.

        IF g_wa_makt-spras = sy-langu.
          g_wa_data-maktx = g_wa_makt-maktx.
        ENDIF.

        g_wa_data-counter = g_wa_data-counter + 1.

      ENDIF.


      IF g_wa_data-spart = 'Z1'.
        g_wa_data-light = '1'.
      ELSEIF g_wa_data-spart = 'LF'.
        g_wa_data-light = '2'.
      ELSE.
        g_wa_data-light = '3'.
      ENDIF.

      MODIFY g_it_data FROM g_wa_data.

    ENDLOOP.

  ENDLOOP.


  IF pa_wri = 'X'.

    LOOP AT g_it_data INTO g_wa_data.

*     Output of the data records
      WRITE: /1 g_wa_data-matnr,
        20 g_wa_data-maktx,
        70 g_wa_data-counter,
        100 g_wa_data-spart.

      IF g_wa_data-spart = 'Z1'.
        WRITE 120 icon_red_light AS ICON.
      ELSEIF g_wa_data-spart = 'LF'.
        WRITE 120 icon_yellow_light AS ICON.
      ELSE.
        WRITE 120 icon_green_light AS ICON.
      ENDIF.

*     Count up the data records
      g_zaehler = g_zaehler + 1.

    ENDLOOP.

  ELSEIF pa_alv = 'X'.

*   Set initial dynpro
    CALL SCREEN 100.

  ENDIF.


END-OF-SELECTION.

* It should only be written in the report version
  IF pa_wri = 'X'.

    WRITE: /.
    WRITE:/1 'Number of the short text: ', g_wa_data-counter,
    70 'Data records: ', g_zaehler,
    110 'Page: ', sy-pagno.
    WRITE: /.

  ENDIF.

*This is written on the end of the page
END-OF-PAGE.
*----------------------------------------------------------------------*
*  MODULE PBO OUTPUT
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'MAIN100'.
  g_repid = sy-repid.
  IF g_custom_container IS INITIAL.
*   Set a value for field LIGHT for each line of your output table.
*   You do not necessarily need to define a field catalog if
*   the rest of your output table is represented by a DDIC structure.
    CREATE OBJECT g_custom_container
           EXPORTING container_name = g_container
    EXCEPTIONS
        cntl_error = 1
        cntl_system_error = 2
        create_error = 3
        lifetime_error = 4
        lifetime_dynpro_dynpro_link = 5.
    IF sy-subrc NE 0.
*   Add your handling, for example
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = g_repid
          txt2  = sy-subrc
          txt1  = 'The control could not be created'(510).
    ENDIF.
*   Create an instance of alv control
    CREATE OBJECT grid1
           EXPORTING i_parent = g_custom_container.
*..............................................
*set some layout-values (Structure LVC_S_LAYO)
*..............................................
*   Set a titlebar for the grid control
    gs_layout-grid_title = 'Materials'(100).
*   Set field EXCP_FNAME of the structure of type LVC_S_LAYO
*   with the name of your additional field.
    gs_layout-excp_fname = g_lights_name.

    gs_layout-excp_rolln = 'ALV_LIGHT'.
*    gs_layout-excp_led   = 'X'.

    gs_layout-zebra = 'X'.
*.............................
* show table on ALV Control
*.............................
*   Provide your Layout-Structure when calling
*   'set_table_for_first_display' (Parameter IS_LAYOUT).
    CALL METHOD grid1->set_table_for_first_display
  EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
    i_structure_name              = 'ZSSS_MMSTAMM_BL'
*    IS_VARIANT                    =
*    I_SAVE                        =
*    I_DEFAULT                     = 'X'
    is_layout                     = gs_layout
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
      CHANGING
        it_outtab                     = g_it_data
*        it_fieldcatalog               = gt_field
*    IT_SORT                       =
*    IT_FILTER                     =
*  EXCEPTIONS
*    INVALID_PARAMETER_COMBINATION = 1
*    PROGRAM_ERROR                 = 2
*    TOO_MANY_LINES                = 3
*    others                        = 4
            .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  ENDIF.

*Control Framework flushes at the end of PBO automatically!
ENDMODULE.                 " PBO  OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
* To react on oi_custom_events:
  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN OTHERS.
* Do nothing
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "PAI INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
*  CALL METHOD G_CUSTOM_CONTAINER->FREE.
*  CALL METHOD CL_GUI_CFW=>FLUSH.
  LEAVE PROGRAM.
ENDFORM.                    "EXIT_PROGRAM
Es waren die loops und endloops etwas "verdreht" ..

lg

Beitrag von DeathGuardian (Expert / 759 / 0 / 3 ) »
Oder wie wärs mit Plan B.

- deine Daten Selectieren
- LOOP über deine ITAB
- im LOOP SELECT SINGLE maktx from makt into deine_wa-matkx where matnr eq deine_wa-matnr AND spras eq sy-langu.

EDIT:
Ums performanter zu machen (bei grösseren Datenmängen)
Spar nämlich ein paar Selects.

Code: Alles auswählen.

TYPES:
  BEGIN OF t_maktx,
    matnr TYPE makt-matnr,
    maktx TYPE makt-maktx,
  END   OF t_maktx.
DATA:
  i_maktx       TYPE HASHED TABLE OF t_maktx WITH UNIQUE KEY matnr,
  wa_maktx      LIKE LINE OF i_maktx,

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*&      Form  READ_MAKTX
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM read_maktx  USING    p_matnr  TYPE matnr
                 CHANGING ch_maktx TYPE maktx.

  CLEAR: ch_maktx, wa_maktx.

  IF p_matnr IS NOT INITIAL.
    READ TABLE i_maktx WITH TABLE KEY matnr = p_matnr
                       INTO wa_maktx TRANSPORTING maktx.
    IF sy-subrc NE 0 .
      SELECT  SINGLE maktx
        INTO  (wa_maktx-maktx)
        FROM  makt
        WHERE matnr EQ p_matnr   AND
              spras EQ sy-langu  .
      wa_maktx-matnr = p_matnr.
      INSERT wa_maktx INTO TABLE i_maktx.
    ENDIF.
    ch_maktx = wa_maktx-maktx .
  ENDIF.

ENDFORM.                    " READ_MAKTX

Beitrag von BabsiCSC (ForumUser / 86 / 0 / 0 ) »
Hello,

hmmm, mal ausprobieren , ..
o.k., danke!

lg

Seite 1 von 1

Vergleichbare Themen

6
Antw.
1925
Views
falsch gesetztes CLEAR !?
von BabsiCSC » 30.06.2008 12:09 • Verfasst in ABAP® Core
1
Antw.
1444
Views
4
Antw.
3759
Views
LOOP in einem LOOP
von Bjuti » 10.09.2013 15:18 • Verfasst in ABAP® für Anfänger
1
Antw.
1772
Views
select falsch?
von barbara » 07.07.2006 10:38 • Verfasst in ABAP® für Anfänger
2
Antw.
1977
Views
RCPDIRO1 falsch, was tun ?
von sapler » 12.10.2005 15:36 • Verfasst in Material Management & Produktionsplanung

Über diesen Beitrag


Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Unbeantwortete Forenbeiträge

Daten an Tabelle binden
Gestern von Bright4.5 1 / 511
aRFC im OO-Kontext
vor 4 Wochen von ralf.wenzel 1 / 2146
Hilfe bei SWEC/SWE2
letzen Monat von retsch 1 / 8742